<!-- templates/datasource_list.html -->
{% extends 'base.html' %}

{% block title %}数据源列表{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3">数据源管理</h1>
        <a href="{% url 'datasource_create' %}" class="btn btn-primary">
            <i class="fa fa-plus"></i> 新建数据源
        </a>
        <h1 class="h3">数据源管理</h1>
    </div>
    
    {% if messages %}
        {% for message in messages %}
            <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        {% endfor %}
    {% endif %}
    
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <th>名称</th>
                            <th>描述</th>
                            <th>创建时间</th>
                            <th>字段数量</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for datasource in data_sources %}
                        <tr>
                            <td>{{ datasource.name }}</td>
                            <td>{{ datasource.description|truncatechars:50 }}</td>
                            <td>{{ datasource.created_at|date:"Y-m-d H:i" }}</td>
                            <td>{{ datasource.fields.count }}</td>
                            <td>
                                <a href="{% url 'field_list' datasource_pk=datasource.pk %}" class="btn btn-sm btn-outline-secondary">
                                    <i class="fa fa-list"></i> 查看字段
                                </a>
                                <a href="{% url 'datasource_update' pk=datasource.pk %}" class="btn btn-sm btn-outline-primary">
                                    <i class="fa fa-edit"></i> 编辑
                                </a>
                                <a href="{% url 'datasource_delete' pk=datasource.pk %}" class="btn btn-sm btn-outline-danger">
                                    <i class="fa fa-trash"></i> 删除
                                </a>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="5" class="text-center text-muted py-4">
                                <i class="fa fa-folder-open-o fa-3x mb-2"></i>
                                <p>暂无数据源，请创建一个新的数据源。</p>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}    